<!--
* description: TPR管理
* author: xuliwen
* createdDate: 2021-01-21
-->
<template>
  <div class="app-container app-container-table">
    <one-table-template
      ref="multipleTable"
      :key="oneTableKey"
      :dynamic-buttons="tableButtons"
      :dynamic-components="tableComponents"
      :dynamic-api-config="apiConfig"
      :dynamic-table-cols="tableCols"
      :dynamic-form-fields="formField"
      :dynamic-is-show-select="false"
      :dynamic-is-init-table="true"
      :dynamic-api-style="'restful'"
    />

    <edit
      :key="editPopupsKey"
      :dynamic-edit-row-data="editRowData"
      :popups-visible="editPopupsVisible"
      :popups-state="editPopupsState"
      :dynamic-api-style="'restful'"
      @close="close"
    />

    <detail
      :key="detailPopupsKey"
      :dynamic-detail-row-data="detailRowData"
      :popups-visible.sync="detailPopupsVisible"
      :popups-state="editPopupsState"
      @closeDetail="closeDetail"
    />
  </div>
</template>
<script>
import { oneTableWithViewTemplateMixins } from '@/components/mixins/oneTableWithViewTemplateMixins'
import OneTableTemplate from '@/components/templates/oneTable'
import api from '@/api/se/tprManagement'
import Vue from 'vue'

export default {
  name: 'TprManagement',

  components: {
    OneTableTemplate,
    Edit: () => import('./edit'),
    Detail: () => import('./detail')
  },
  // 组件混入对象
  mixins: [oneTableWithViewTemplateMixins],

  // 阻塞路由预加载网格中组件的数据
  beforeRouteEnter(to, from, next) {
    Vue.prototype.$ConfigCache.CacheConfig.initData([to.path, ''], function() {
      next()
    })
  },

  data() {
    // 页面标识（与上面beforeRouteEnter中的对应）
    const viewPageCode = this.$route.path

    // 绑定事件配置化事件
    this.$ConfigCache.CacheConfig.bindEvent(this, [viewPageCode])

    return {
      detailPopupsKey: '1',
      detailRowData: {},
      detailPopupsVisible: false,

      editRowData: {},
      // 网格查询API配置对象
      apiConfig: api.queryTPRMaintain,

      // 动态组件-按钮
      tableButtons: [
        {
          compKey: 'btnKey1',
          type: 'primary',
          size: 'small',
          name: 'search',
          clickEvent: () => this.queryTable(1),
          text: this.$t('sys.button.query'), // 查询
          position: 'right',
          fuzzySearch: true
        },
        {
          compKey: 'btnKey2',
          type: '',
          size: 'small',
          name: 'reset',
          clickEvent: () => this.reset(),
          text: this.$t('sys.button.reset'),
          position: 'right' // 重置
        }
        // {
        //   compKey: "btnKey3",
        //   type: "",
        //   size: "small",
        //   name: "add",
        //   clickEvent: this.add,
        //   text: this.$t("sys.button.add"), // 新增
        //   position: "left",
        // },
        // {
        //   compKey: 'btnKey4',
        //   type: 'primary',
        //   size: 'small',
        //   clickEvent: () => this.importcar(),
        //   text: '导入',
        //   name: 'import', // 按钮图标样式
        //   position: 'upload'
        // },
        // {
        //   compKey: 'btnKey5',
        //   type: '',
        //   size: 'small',
        //   clickEvent: () => this.download(),
        //   text: '下载模板',
        //   name: 'download',
        //   position: 'right'
        // },
        // {
        //   compKey: "btnKey3",
        //   type: "",
        //   size: "small",
        //   clickEvent: () => this.exportExcel111(),
        //   text: "导出",
        //   name: "export",
        //   position: "left",
        // },
      ],

      // 动态组件-查询条件
      tableComponents:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
          .tableComponents.length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path]
            .tableComponents
          : [
            {
              compKey: 'compKey1',
              labelName: 'TPR单编号：',
              codeField: 'tprCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey2',
              labelName: '门店编码：',
              codeField: 'dlrCode',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey3',
              labelName: '门店名称：',
              codeField: 'dlrName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey4',
              labelName: '下发日期：',
              codeField: 'createdDate',
              component: () =>
                import('@/components/org/datePicker/datePicker.vue'),
              type: 'datePicker',

              isMul: false,
              isMust: true
            },
            {
              compKey: 'compKey5',
              labelName: 'VIN：',
              codeField: 'vin',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey6',
              labelName: '回复人：',
              codeField: 'empName',
              component: () => import('@/components/org/commonInput'),
              type: 'inputText',
              isMul: false,
              isMust: false
            },
            {
              compKey: 'compKey7',
              labelName: '回复日期：',
              codeField: 'replyDate',
              component: () =>
                import('@/components/org/datePicker/datePicker.vue'),
              type: 'datePicker',
              format: 'yyyy-MM-dd',
              isMul: false,
              isMust: false
            }
            // {
            //   compKey: 'compKey8',
            //   labelName: '状态：',
            //   codeField: 'status',
            //   component: () => import('@/components/org/LookupValue'),
            //   oFields: 'statusId,statusText',
            //   options: [
            //     { statusId: '1', statusText: '下发' },
            //     { statusId: '0', statusText: '已回复' }
            //   ],
            //   type: 'dropdownList',
            //   isMul: false,
            //   isMust: false
            // }
          ],

      // 动态生成网格列
      tableCols:
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path] &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols &&
        this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          .length > 0
          ? this.$ConfigCache.CacheConfig.cacheData[this.$route.path].tableCols
          : [
            {
              prop: 'tprId',
              label: 'TPRid',
              hidden: true,
              alwaysHidden: true
            },
            {
              prop: 'controlBtn1',
              label: '操作',
              minWidth: 180,
              isComponent: true,
              comps: [
                {
                  compKey: 'propKey1',
                  labelName: '回复',
                  // rowFileds: 'show:tprStutas-1',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => this.edit(index)

                },
                {
                  compKey: 'propKey2',
                  labelName: '详情',
                  component: () => import('@/components/org/linkButton'),
                  clickEvent: (index) => { this.detail(index) }

                }
              ]
            },
            {
              prop: 'claimCode',
              label: '申请单号'
            },
            {
              prop: 'dlrCode',
              label: '门店编码'
            },

            {
              prop: 'dlrName',
              label: '门店名称'
            },
            {
              prop: 'createdDate',
              label: '下发日期'
            },
            {
              prop: 'empName',
              label: '回复人'
            },
            {
              prop: 'tprStutas',
              label: '状态'
            },
            {
              prop: 'replyDate',
              label: '回复日期'
            }
            // {
            //   prop: "areaRemark",
            //   label: "备注",
            // },
          ],

      // 表单查询数据
      formField: this.$utils.getFormField(
        this,
        {
          tprCode: '',
          dlrCode: '',
          dlrName: '',
          vin: '',
          empName: '',
          replyDate: '',
          createdDate: ''
        },
        this.$ConfigCache.CacheConfig.cacheData[viewPageCode]
      )
    }
  },

  mounted() {
    // 列表查询
    this.queryTable(1)
  },

  methods: {
    // 编辑获取数据
    edit(index) {
      this.editPopupsState = 'edit'
      this.editPopupsVisible = true
      this.editRowData = this.$refs['multipleTable'].list[index]
    },

    detail(index) {
      this.editPopupsState = 'edit'
      this.detailPopupsVisible = true
      this.detailRowData = this.$refs['multipleTable'].list[index]
    },
    goPage(index) {
      const paramsData = this.$refs['multipleTable'].list[index]
      this.$router.push({ name: 'returnNoticeReply', params: paramsData })
    },
    // 关闭详情弹窗
    closeDetail() {
      this.detailPopupsVisible = false
      this.detailPopupsKey = this.$utils.generateId()
    }
  }
}
</script>
